package com.ly.system.auth;


import com.ly.system.entity.TbMenu;

import com.ly.system.service.TbMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import org.springframework.util.AntPathMatcher;

import java.util.Collection;
import java.util.List;

public class MyFilterInvocationSecurityMetadataSource implements FilterInvocationSecurityMetadataSource

    {
    AntPathMatcher antPathMatcher = new AntPathMatcher();
    @Autowired
    TbMenuService tbMenuService ;
//    @Override
//    public Collection<ConfigAttribute> getAttributes(Object o) throws IllegalArgumentException {
//        //获取请求地址
//        String requestUrl = ((FilterInvocation) o).getRequestUrl();
//        //查询具体某个接口的权限
//        List<TbMenu> permissionList =  tbMenuService.list();
//        if(permissionList == null || permissionList.size() == 0){
//            //请求路径没有配置权限，表明该请求接口可以任意访问
//            return null;
//        }
//        String[] attributes = new String[permissionList.size()];
//        for(int i = 0;i<permissionList.size();i++){
//            attributes[i] = permissionList.get(i).getPerms();
//        }
//        return SecurityConfig.createList(attributes);
//    }

        @Override
        public Collection<ConfigAttribute> getAttributes(Object o) throws IllegalArgumentException {
            return null;
        }

        @Override
    public Collection<ConfigAttribute> getAllConfigAttributes() {
        return null;
    }

    @Override
    public boolean supports(Class<?> aClass) {
        return true;
    }
}